package com.ghj.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {

//        this.setFieldValByName("createTime",new Date(),metaObject);
//        this.setFieldValByName("loginTime",new Date(),metaObject);
        if(metaObject.hasGetter("createTime")){
        this.fillStrategy(metaObject, "createTime", new Date());}
        else {
            this.fillStrategy(metaObject, "loginTime", new Date());
        }

    }

    @Override
    public void updateFill(MetaObject metaObject) {

    }

}
